package 第五轮工作.绍兴文理学院;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 第五轮工作.天津理工.TJLUBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SXWLU {
    public static void main(String[] args) throws IOException {
        SXWLUBean sxwluBean;
        List<SXWLUBean> sxwluBeans = new ArrayList<>();
        String url = "https://jdxy.usx.edu.cn/szdw/yjsds.htm";
        Connection connect = Jsoup.connect(url);
        Document post = connect.post();
        for (Element tbody : post.getElementsByTag("tbody")) {
            for (Element td : tbody.getElementsByTag("td")) {
                for (Element a : td.getElementsByTag("a")) {

                    if (!a.attr("href").equals("")) {
                        String href = a.attr("href").substring(3);
                        Connection connect1 = Jsoup.connect("https://jdxy.usx.edu.cn/" + href);
                        Document post1 = connect1.post();
                        for (Element vNewsContent : post1.getElementsByClass("v_news_content")) {
                            sxwluBean = new SXWLUBean();
                            int p = vNewsContent.getElementsByTag("p").size();
                            //姓名
//                            System.out.println(vNewsContent.getElementsByTag("p").get(1).text());
                            sxwluBean.setName(vNewsContent.getElementsByTag("p").get(1).text());
                            //邮箱
//                            System.out.println(vNewsContent.getElementsByTag("p").get(p - 1).text());
                            sxwluBean.setQy(vNewsContent.getElementsByTag("p").get(p - 1).text());
                            sxwluBeans.add(sxwluBean);
                        }
                    }
                }

            }

        }
        EasyExcel.write("src/main/java/第五轮工作/绍兴文理学院/SXWLU.xlsx", SXWLUBean.class).sheet("user").doWrite(sxwluBeans);


    }
}
